<%
	Response.CacheControl = "no-cache"
	Response.AddHeader "Pragma", "no-cache"	
	Response.Expires = -1 
%>
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Calendar</title>
</head>
<link rel=stylesheet href="..\css\calendar.css" type="text/css">
<body leftmargin=0 border=0 topmargin=0 SCROLL=NO style="background:buttonface;border-left:solid gray 0;border-top:solid gray 0;border-right:solid gray 0;border-bottom:solid gray 0;cursor: default;">
<form name=frm method=post>
<DIV align=center id=calendar></DIV>
<script language=vbscript>

	Dim calPopup
	Dim intMonth
	Dim intYear
	Dim intColumnSunday
	Dim intColumnSaturday
	Dim intActiveDay
	Dim intActiveMonth
	Dim intActiveYear
	Dim txtParentElName
	Dim intFirstDayofWeek
	
	sub window_onLoad 
			
		intYear=Year(now)			
		intMonth=Month(now)

		intActiveMonth=Month(now)
		intActiveYear=Year(now)
		intActiveDay=Day(now)
		
		txtParentElName=id
		intFirstDayofWeek=1
		
		if intFirstDayofWeek=1 then
			intColumnSunday=1
			intColumnSaturday=7
		else
			intColumnSunday=9-intFirstDayofWeek
			intColumnSaturday=8-intFirstDayofWeek
		end if
		intColumnSunday=1
		intColumnSaturday=7
				
		calendar.innerHtml = popGenerateView(intMonth, intYear)
			
	End Sub	
	
	Sub popChangeDate(intAmount,strMeans)
	
		myDate = dateSerial(intYear,intMonth,1)
		myDate = dateAdd(strMeans,intAmount,myDate)	
		intMonth = month(myDate)
		intYear = year(myDate)
		calendar.innerHtml = popGenerateView(intMonth, intYear)

	End Sub
	Sub popSelectDate(msg)
		p=split(msg)
		vb_date=DateSerial( p(2), p(1), p(0) )
		strdate=CStr(Month(vb_date)) &"/"& CStr(Day(vb_date)) &"/"& CStr(Year(vb_date))
		'frm.action="test2tc.asp?bComm=""&strdate=" & CStr(Month(vb_date)) &"/"& CStr(Day(vb_date)) &"/"& CStr(Year(vb_date))
		'frm.target="main"
		'frm.submit()
		document.cookie="changedate="+strdate
		window.close()
	End Sub

	Function ZeroPad(byval str, byval iSize)
		ZeroPad = String((iSize - Len(str)), "0") & Trim(str)
	End Function
	
	Function popGenerateView(m,y)

		Dim FirstDay, TheDay 
		Dim DaysInMonth, PrevDaysInMonth 
		Dim ThisMonth, PrevMonth, NextMonth
		
		CS = ""
		monthmode=0
		TheDay = 0
		TheNextDay=1

		FirstDay = WeekDay(Dateserial(y,m,1), intfirstdayofweek) 
		DaysInMonth= Day(Dateserial(y,m+1,1)-1)
		PrevDaysInMonth= Day(Dateserial(y,m,1)-1)
		ThisMonth=MonthName(Month(Dateserial(y,m,1))) & " " & Year(Dateserial(y,m,1))
		PrevMonth=MonthName(Month(Dateserial(y,m-1,1))) & " " & Year(Dateserial(y,m,1))
		NextMonth=MonthName(Month(Dateserial(y,m+1,1))) & " " & Year(Dateserial(y,m,1))
		Sothang=Month(Dateserial(y,m,1))
		strTenthang=TenThang(Sothang) & " " & Year(Dateserial(y,m,1))
	
		goMonthBack = "<span class=changeDate id=monthBack style=""cursor:hand"" onclick=""call parent.popChangeDate(-1,'m')"" language=vbscript><img width=13 height=18 src='..\Images\pick_left.gif'></span>"
		goMonthForward = "<span class=changeDate id=monthForward style=""cursor:hand"" onmousedown=""Call parent.popChangeDate(1,'m')"" language=vbscript><img width=13 height=18 src='..\Images\pick_right.gif'></span>"
		goYearBack = "<span class=changeDate id=back style=""cursor:hand"" onclick=""call parent.popChangeDate(-1,'yyyy')"" language=vbscript><img width=13 height=18 src='..\Images\pick_left_year.gif'></span>"
		goYearForward = "<span class=changeDate id=forward style=""cursor:hand"" onclick=""call parent.popChangeDate(1,'yyyy')"" language=vbscript><img width=13 height=18 src='..\Images\pick_right_year.gif'></span>"

		CS = CS & "<TABLE style=""position:absolute; border: 2px inset"" align=center CLASS=Calendar CELLPADDING=0 CELLSPACING=0 id=CalendarTable width=100%>"	
		CS = CS & "<TR CLASS=CalendarMonthTitle>"
		CS = CS & "<TH COLSPAN=7>"
			CS = CS & "<table border=0 cellpadding=0 cellspacing=0 width=100% class=small>"
			CS = CS & "<td class=small width=10>" & goYearBack & "</td>"
			CS = CS & "<td class=small width=10>" & goMonthBack & "</td>"
			CS = CS & "<td class=small TITLE='" & strTenthang & "'>" & strTenthang & "</th>"
			CS = CS & "<td class=small width=10>" & goMonthForward & "</td>"
			CS = CS & "<td class=small width=10>" & goYearForward & "</td>"
			CS = CS & "</table>"	
		CS = CS & "</TH>"
		CS = CS & "</TR>"

		CS = CS & "<TR>"
		for intDayNumber = 1 to 7
			strDayName = TenNgay(intDayNumber)
			CS = CS & "<TH TITLE='"& strDayName &"'>" & TenTatNgay(intDayNumber) & "</TH>"
		next
		CS = CS & "</TR>"
	
		for Row=1 to 6
	
			CS = CS & "<TR >"
			for Col=1 to 7	
				if Row=1 then
					if Col=FirstDay Then 
						TheDay=1
					else
						if Col<FirstDay then TheDay=(PrevDaysInMonth-(FirstDay))+(Col-1)+2
					end if
				end if
	
				if Col<FirstDay and row=1 then
					dte=dateserial(y,m-1,TheDay)
					strDayTitle = formatDateTime(dte, vbLongDate)
					strStart=Zeropad(day(dte), 2)+" "+Zeropad(month(dte), 2)+" "+ZeroPad(year(dte),4)
					intMonthActive=m-1
				else
					if TheDay>DaysInMonth then
						dte=dateserial(y,m,TheDay)
						strDayTitle = formatDateTime(dte, vbLongDate)
						strStart=Zeropad(day(dte), 2)+" "+Zeropad(month(dte), 2)+" "+ZeroPad(year(dte),4)
						intMonthActive=m
					else
						dte=dateserial(y,m,TheDay)
						strDayTitle = formatDateTime(dte, vbLongDate)
						strStart=Zeropad(day(dte), 2)+" "+Zeropad(month(dte), 2)+" "+ZeroPad(year(dte),4)
						intMonthActive=m
					end if
				end if				
				
				if TheDay = intActiveDay and intMonth=intActiveMonth and intYear=intActiveYear and intMonth=intMonthActive then 
					CS = CS & "<TD CLASS=CalendarToDay onclick=""javascript:parent.popSelectDate('"& strStart&"')"" onmouseover=""javascript:window.event.srcElement.className='hovered'"" onMouseOut=""javascript:window.event.srcElement.className='CalendarToDay'""  start="""& strStart&""" >" & TheDay
				else
					if row=1 and Col<FirstDay and monthmode<>2 then
						CS = CS & "<TD CLASS=CalendarEmptyDay onclick=""javascript:parent.popSelectDate('"& strStart&"')"" onmouseover=""javascript:window.event.srcElement.className='hovered'"" onMouseOut=""javascript:window.event.srcElement.className='CalendarEmptyDay'"" id=""cell"" start="""& strStart &""" >" & TheDay
					else
						if (row>1 and TheDay>DaysInMonth) or monthmode=2 then
							CS = CS & "<TD CLASS=CalendarEmptyDay onclick=""javascript:parent.popSelectDate('"& strStart&"')"" onmouseover=""javascript:window.event.srcElement.className='hovered'"" onMouseOut=""javascript:window.event.srcElement.className='CalendarEmptyDay'"" id=""cell"" start="""& strStart&""" >" & TheNextDay
							TheNextDay=TheNextDay+1
						else
							if col=intColumnSunday or col=intColumnSaturday then
								CS = CS & "<TD CLASS=CalendarWeekendDay onclick=""javascript:parent.popSelectDate('"& strStart&"')"" onmouseover=""javascript:window.event.srcElement.className='hovered'"" onMouseOut=""javascript:window.event.srcElement.className='CalendarWeekendDay'"" id=""cell"" start="""& strStart&""" >" & TheDay
							else
								CS = CS & "<TD CLASS=CalendarDay onclick=""javascript:parent.popSelectDate('"& strStart&"')"" onmouseover=""javascript:window.event.srcElement.className='hovered'"" onMouseOut=""javascript:window.event.srcElement.className='CalendarDay'"" id=""cell"" start="""& strStart&""" >" & TheDay
							end if
						end if
					end if
				end if		

				if TheDay > 0 then TheDay=TheDay+1	
				CS = CS & "</TD>"
	
			next
	
			CS = CS & "</TR>"
	
			if (TheDay > DaysInMonth) and monthmode<>2 then 
				monthmode=2
			end if
	
		next

		popGenerateView = CS & "</TABLE>"

	End Function
	Function TenNgay(intDayNumber)
		select case intDayNumber
			case 1
				TenNgay="Chủ Nhật"
			case 2
				TenNgay="Thứ Hai"
			case 3
				TenNgay="Thứ Ba"
			case 4
				TenNgay="Thứ Tư"
			case 5
				TenNgay="Thứ Năm"
			case 6
				TenNgay="Thứ Sáu"
			case 7
				TenNgay="Thứ Bẩy"
		End select
	End Function
	Function TenTatNgay(intDayNumber)
		select case intDayNumber
			case 1
				TenTatNgay="CN"
			case 2
				TenTatNgay="H"
			case 3
				TenTatNgay="B"
			case 4
				TenTatNgay="T"
			case 5
				TenTatNgay="N"
			case 6
				TenTatNgay="S"
			case 7
				TenTatNgay="B"
		End select
	End Function
	Function TenThang(intMonthNumber)
		select case intMonthNumber
			case 1
				TenThang="Tháng Giêng"
			case 2
				TenThang="Tháng Hai"
			case 3
				TenThang="Tháng Ba"
			case 4
				TenThang="Tháng Tư"
			case 5
				TenThang="Tháng Năm"
			case 6
				TenThang="Tháng Sáu"
			case 7
				TenThang="Tháng Bảy"
			case 8
				TenThang="Tháng Tám"
			case 9
				TenThang="Tháng Chín"
			case 10
				TenThang="Tháng Mười"
			case 11
				TenThang="Tháng Mười Một"
			case 12
				TenThang="Tháng Mười Hai"
		End select
	End Function
</SCRIPT>
</form>
</body>
</html>